﻿/*************************************************************
 * Software of blackcore
 *
 * CLRVersion:4.0.30319.586
 * MachineName:SPACE
 * Author:Andy Huang
 * Email:itblackhole@gmail.com
 * DateTime：6/26/2013 2:46:13 PM
 * Function：
 *************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SobFS.Common;

namespace SobFS.Web.backend.manage.usergroup
{
    public partial class Edit : SobFS.Web.UI.BackendPage
    {
        #region ******************************Private Property******************************
        private int id = 0;
        #endregion ******************************Private Property******************************


        #region ******************************Public Property******************************
        #endregion ******************************Public Property******************************


        #region ******************************Structure******************************
        protected void Page_Load(object sender, EventArgs e)
        {
            this.id = RequestHelper.GetQueryInt("Id");
            if (!Page.IsPostBack)
            {   
                LoadDataById();
            }
        }
        #endregion  ******************************Structure******************************
        

        #region ******************************Private Method******************************
        void LoadDataById()
        {
            Model.SysGroup model = new BLL.SysGroup().GetModel(this.id);
            if (model != null)
            {
                this.rblIsEnabled.SelectedValue = model.IsEnabled ? "1" : "0";
                this.txtName.Text = model.Name;
                this.txtDescription.Text = model.Description;
            }
            else
            {
                JsMessageBox("数据加载失败！", "List.aspx", UI.JsMessageBoxCss.Error);
            }
        }
        #endregion ******************************Private Method******************************


        #region ******************************Public Method******************************
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.SysGroup model = new BLL.SysGroup().GetModel(this.id);
            if (model == null)
            {
                JsMessageBox("操作失败，未获取正确数据！", string.Empty, UI.JsMessageBoxCss.Error);
                return;
            }
            model.IsEnabled = int.Parse(this.rblIsEnabled.SelectedValue) == 0 ? false : true;           
            model.Name = this.txtName.Text.Trim();          
            model.Description = this.txtDescription.Text.Trim();
            if (new BLL.SysGroup().Update(model))
            {
                JsMessageBox("操作成功！", "List.aspx", UI.JsMessageBoxCss.Success);
            }
            else
            {
                JsMessageBox("操作失败！", string.Empty, UI.JsMessageBoxCss.Error);
            }

        }
        #endregion ******************************Public Method******************************
    }
}